/*
 * 컴파일을 위해 올려 놓은 소스 입니다.
 * 서버에 반영하지 마시고 다른국가에 적용할 경우 서버에 있는 class 를 카피해서 사용하십시오.
 * 
 */
/*
 * Created on 2004. 9. 29.
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package com.pushmsg.OmaOtaConf.OmaOtaObject; 

import java.util.*;
/**
 * @author dgchun
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class PXLOGICAL 
{
	String country = null;
	String operator = null;
	String bearer = null;
	String nettype = null;
	String id = null;
	String name = null;	
	String pxaddress = null;
	String port = null;
	String napid = null;
	String appType = null;
	private Hashtable profile = null;
	PXPHYSICAL physical = null;
	
	public PXLOGICAL(String country, String op, String appType, String bearer, String nettype, String napid)
	{
		this.country = country;
		this.operator = op;
		this.appType = appType;
		this.bearer = bearer;
		this.nettype = nettype;
		this.napid = napid;
		id  = operator.toUpperCase() + "-" + bearer.toUpperCase() + "-" + nettype.toUpperCase();
	}
	
	private boolean getSetting()
	{
		String file = null;
		if(nettype.equals("wap"))
			file = Constants.FILEPATH + country.toLowerCase() + "/" + operator +  "_" + bearer + "_" + nettype + ".xml";
		else
			file = Constants.FILEPATH + country.toLowerCase() + "/" + operator + "_" + appType + "_" + bearer + "_" + nettype + ".xml";
		ProfileReader pr = new ProfileReader(file);
		profile = pr.getProfile();
		if(profile==null)
			return false;		
		//name = id;
		port = (String)profile.get("PORT");
		
		pxaddress = (String)profile.get("PROXY");
		
		if(pxaddress==null)
			return false;
		physical = new PXPHYSICAL(operator, napid, pxaddress);
		return true;		
	}	
	
	public boolean isProxyEnabled()
	{
		return getSetting();
	}
	
	public void setProxyName(String name)
	{
		this.name = name;		
	}
	
	public String getProxyId()
	{
		return id;
	}
	
	public int getData(byte[] buffer, int index)
	{
		if(getSetting()==false)
			return 0;
		int startPos = index;
		//<characteristic type="PXLOGICAL">
		buffer[index++] = (byte)0xC6;
		buffer[index++] = (byte)0x51;
		buffer[index++] = (byte)0x01;
		//<parm name="PROXY-ID" value=""/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x15;
		buffer[index++] = (byte)0x06;
		buffer[index++] = (byte)0x03;
		System.arraycopy(id.getBytes(), 0, buffer, index, id.length());
		index += id.length();
		buffer[index++] = (byte)0x00;
		buffer[index++] = (byte)0x01;
		//<parm name="NAME" value=""/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x07;
		buffer[index++] = (byte)0x06;
		buffer[index++] = (byte)0x03;
		System.arraycopy(name.getBytes(), 0, buffer, index, name.length());
		index += name.length();
		buffer[index++] = (byte)0x00;
		buffer[index++] = (byte)0x01;
		
		//<characteristic type="PORT">
		buffer[index++] = (byte)0xC6;
		buffer[index++] = (byte)0x53;
		buffer[index++] = (byte)0x01;
		//<parm name="PORTNBR" value=""/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x23;
		buffer[index++] = (byte)0x06;
		buffer[index++] = (byte)0x03;
		System.arraycopy(port.getBytes(), 0, buffer, index, port.length());
		index += port.length();
		buffer[index++] = (byte)0x00;
		buffer[index++] = (byte)0x01;
		//<parm name="SERVICE" value=""/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x24;
		buffer[index++] = (byte)0x06;
		buffer[index++] = (byte)0xD2;
		buffer[index++] = (byte)0x01;		
		buffer[index++] = (byte)0x01;
		
		index += physical.getData(buffer, index);
		buffer[index++] = (byte)0x01;
		
		return index - startPos;
	}
}
